<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2017/12/2
  Time: 17:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <base href="${pageContext.request.contextPath}/">
    <title> 编辑销售机会</title>
    <link href="css/style.css" rel="stylesheet" type="text/css">
    <script src="js/jquery-1.9.0.js"></script>
    <script src="script/common.js"></script>
    <script>
        inputdateObject.value=YYYY-MM-DD
    </script>
</head>
<body>
<div class="page_title">销售机会管理&nbsp; &gt; 编辑销售机会</div>
<div class="button_bar">
    <button class="common_button" onclick="help('');">帮助</button>
    <button class="common_button" onclick="back();">返回</button>
    <button class="common_button" id="save">保存</button>
</div>
<form action="salc/editUpdate" method="get" id="formx">
<table class="query_form_table">
    <tr>
        <th>编号</th>
        <td><input readonly value="${salChance.chcId}" name="chcId" /></td>
        <th>机会来源</th>
        <td>
            <input name="chcSource" size="20" value="${salChance.chcSource}" /></td>
    </tr>
    <tr>
        <th>客户名称</th>
        <td><input value="${salChance.chcCustName}"  name="chcCustName"/><span class="red_star">*</span></td>
        <th>成功机率（%）</th>
        <td><input value="${salChance.chcRate}" name="chcRate"/><span class="red_star">*</span></td>
    </tr>
    <tr>
        <th>概要</th>
        <td colspan="3"><input value="${salChance.chcTitle}" name="chcTitle" size="52" /><span class="red_star">*</span></td>
    </tr>
    <tr>
        <th>联系人</th>
        <td><input name="chcLinkman" value="${salChance.chcLinkman}" size="20" /></td>
        <th>联系人电话</th>
        <td><input name="chcTel" value="${salChance.chcTel}" size="20" /></td>
    </tr>
    <tr>
        <th>机会描述</th>
        <td colspan="3"><textarea rows="6" cols="50" name="chcDesc">${salChance.chcDesc}</textarea><span class="red_star">*</span></td>
    </tr>
    <tr>
        <th>创建人</th>
        <td>
            <input  type="hidden" name="chcCreateBy" id="chcCreateBy">
            <select name="chcCreateId" id="chcCreateId">
            </select><span class="red_star">*</span></td>
        <th>创建时间</th>
        <td><input id="chc_CreateDate" name="chc_CreateDate" type="date" required/>
            <input id="chc_CreateDateTure" type="hidden" value="${salChance.chcCreateDate}">
    </tr>
</table>
<br />
<table disabled class="query_form_table" id="table1">
    <tr>
        <th>指派给</th>
        <td>
            <input  type="hidden" name="chcDueTo" id="chcDueTo">
            <select name="chcDueId" id="chcDueId">
            </select><span class="red_star">*</span>
        </td>
        <th>指派时间</th>
        <td><input id="chc_DueDate" name="chc_DueDate" type="date"  required /><span class="red_star">*</span>
            <input id="chc_DueDateTure" type="hidden" value="${salChance.chcDueDate}">
        </td>
    </tr>
</table>
</form>
<script>
    $(function () {
        /*var time=$("#chcCreateDate");
        var newDate = new Date();
        var val=$.trim($(time).text());


        if(val == '0'){
            $(time).html("");
        }else {
            newDate.setTime(val);
            $(time).html(newDate.toLocaleDateString());
        }*/
        var str ="";
        var chc_DueDateTure= $("#chc_DueDateTure");
        var chc_DueDate= $("#chc_DueDate");
        var newDate = new Date();
        var val=$.trim($(chc_DueDateTure).val());
        if(val != '0'){
            newDate.setTime(val);
            var year =newDate.getFullYear();
            var month = newDate.getMonth()+1;
            var day = newDate.getDate();
            str =year+"-"+(month<10?("0"+month):month)+"-"+(day<10?("0"+day):day);
        }else {
            str = "";
        }
        chc_DueDate.val(str);

        var chc_CreateDateTure= $("#chc_CreateDateTure");
        var chc_CreateDate= $("#chc_CreateDate");
        val=$.trim($(chc_CreateDateTure).val());
        if(val != '0') {
            newDate.setTime(val);
            year = newDate.getFullYear();
            month = newDate.getMonth() + 1;
            day = newDate.getDate();
            str = year + "-" + (month < 10 ? ("0" + month) : month) + "-" + (day < 10 ? ("0" + day) : day);
        }else {
            str = "";
        }
        chc_CreateDate.val(str);



        $.get("salc/userall", function (data) {
            console.log(data);
            var chcDueId = $("#chcDueId");
            var chcDueTo = $("#chcDueTo");
            var chcCreateId = $("#chcCreateId");
            var chcCreateBy = $("#chcCreateBy");

            $.each(data, function (i, item) {
                var option = '<option value=' + item.usrId + ' >' + item.usrName + '</option>';
                chcDueId.append($(option));
                chcCreateId.append($(option));
            });
            $("#chcDueId option[value='${salChance.chcDueId}']").attr("selected","selected");
            $("#chcCreateId option[value='${salChance.chcCreateId}']").attr("selected","selected");
            var option = $("#chcDueId option:selected");
            var usrName = $(option).text();
            chcDueTo.val(usrName);
            option = $("#chcCreateId option:selected");
            usrName = $(option).text();
            chcCreateBy.val(usrName);
        });

        $("#chcDueId").change(function () {
            var chcDueTo = $("#chcDueTo");
            var option = $("#chcDueId option:selected");
            var usrName = $(option).text();
            chcDueTo.val(usrName);
        });
        $("#chcCreateId").change(function () {
            var chcCreateId = $("#chcCreateId");
            var chcCreateBy = $("#chcCreateBy");
            var option = $("#chcCreateId option:selected");
            var usrName = $(option).text();
            chcCreateBy.val(usrName);
        })

        $("#save").click(function () {
            alert(1);
            $("#formx").submit();
        })

    });
</script>
<script>
    setCurTime('t1');
    setCurTime('t2');
</script>
</body>
</html>
